home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / config / auto-aux / align.c next >
Encoding:
C/C++ Source or Header  |  1996-07-03  |  1.4 KB  |  97 lines  |  [TEXT/R*ch]

  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include <setjmp.h>
  4.  
  5. long foo;
  6.  
  7. void access16(p)
  8.      short * p;
  9. {
  10.   foo = *p;
  11. }
  12.  
  13. void access32(p)
  14.      long * p;
  15. {
  16.   foo = *p;
  17. }
  18.  
  19. jmp_buf failure;
  20.  
  21. void sig_handler(dummy)
  22.      int dummy;
  23. {
  24.   longjmp(failure, 1);
  25. }
  26.  
  27. int test(fct, p)
  28.      void (*fct)();
  29.      char * p;
  30. {
  31.   int res;
  32.  
  33.   signal(SIGSEGV, sig_handler);
  34.   signal(SIGBUS, sig_handler);
  35.   if(setjmp(failure) == 0) {
  36.     fct(p);
  37.     res = 0;
  38.   } else {
  39.     res = 1;
  40.   }
  41.   signal(SIGSEGV, SIG_DFL);
  42.   signal(SIGBUS, SIG_DFL);
  43.   return res;
  44. }
  45.  
  46. jmp_buf timer;
  47.  
  48. void alarm_handler(dummy)
  49.      int dummy;
  50. {
  51.   longjmp(timer, 1);
  52. }
  53.  
  54. void use(n)
  55.      int n;
  56. {
  57.   return;
  58. }
  59.  
  60. int speedtest(p)
  61.      char * p;
  62. {
  63.   int * q;
  64.   volatile int total;
  65.   int i;
  66.   volatile int sum;
  67.  
  68.   signal(SIGALRM, alarm_handler);
  69.   sum = 0;
  70.   if (setjmp(timer) == 0) {
  71.     alarm(1);
  72.     total = 0;
  73.     while(1) {
  74.       for (q = (int *) p, i = 1000; i > 0; q++, i--)
  75.         sum += *q;
  76.       total++;
  77.     }
  78.   }
  79.   use(sum);
  80.   signal(SIGALRM, SIG_DFL);
  81.   return total;
  82. }
  83.  
  84. main()
  85. {
  86.   long n[1001];
  87.   int speed_aligned, speed_unaligned;
  88.  
  89.   if (test(access16, (char *) n + 1)) exit(1);
  90.   if (test(access32, (char *) n + 1)) exit(1);
  91.   if (test(access32, (char *) n + 2)) exit(1);
  92.   speed_aligned = speedtest((char *) n);
  93.   speed_unaligned = speedtest((char *) n + 1);
  94.   if (speed_aligned >= 3 * speed_unaligned) exit(1);
  95.   exit(0);
  96. }
  97.